package com.jzo2o.customer.controller.consumer;

import com.jzo2o.api.customer.dto.response.AddressBookResDTO;
import com.jzo2o.common.model.PageResult;
import com.jzo2o.customer.model.dto.request.AddressBookPageQueryReqDTO;
import com.jzo2o.customer.model.dto.request.AddressBookUpsertReqDTO;
import com.jzo2o.customer.service.IAddressBookService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description AddressBookController
 * @Author apeng
 * @Date 2024-12-03
 */
@RestController
@RequestMapping("/consumer/address-book")
@Api(tags = "地址簿")
public class AddressBookController {

    @Autowired
    private IAddressBookService addressBookService;

    @PostMapping
    @ApiOperation("新增地址簿")
    public void insertAddressBook(@RequestBody AddressBookUpsertReqDTO dto){
        addressBookService.insertAddressBook(dto);
    }

    @GetMapping("page")
    @ApiOperation("地址簿查询")
    public PageResult<AddressBookResDTO> getAddressBook(AddressBookPageQueryReqDTO dto){
        return addressBookService.getAddressBook(dto);
    }

    @GetMapping("{id}")
    @ApiOperation("编辑地址簿")
    public AddressBookResDTO getByIdAddress(@PathVariable Long id){
        return addressBookService.getByIdAddress(id);
    }

    @PutMapping("{id}")
    @ApiOperation("修改地址簿")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "地址簿id", dataType = "Long"),
            @ApiImplicitParam(name = "dto", value = "地址簿接受参数")
    }
    )
    public void updateAddressBook(
            @PathVariable Long id,
            @RequestBody AddressBookUpsertReqDTO dto){
         addressBookService.updateAddressBook(id,dto);
    }

    @DeleteMapping("batch")
    @ApiOperation("批量删除地址簿")
    public void batchDeleteAddressBook(@RequestBody List<String> ids){
        addressBookService.batchDeleteAddressBook(ids);
    }

    @PutMapping("default")
    @ApiOperation("取消默认地址")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "地址簿id",dataType = "Long",required = true),
            @ApiImplicitParam(name = "flag",value = "默认地址状态",dataType = "Integer",required = true)
    }
    )
    public void setDefaultAddressBook(Long id,Integer flag){
        addressBookService.setDefaultAddressBook(id,flag);
    }

    @GetMapping("defultAddress")
    @ApiOperation("获取默认地址")
    public AddressBookResDTO getDefultAddress(){
        return addressBookService.getDefultAddress();
    }

}
